import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["__id", "_status"],
    _excluded2 = ["__id", "_status"],
    _excluded3 = ["__id", "_status"];

/*
 * DataSourceApplication 数据源应用配置
 * @date: 2020-04-22
 */
import intl from 'utils/intl';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var isTenant = isTenantRoleLevel();
var apiPrefix = isTenant ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId) : "".concat(CPAAS_PLATFORM, "/v1"); // 表格ds

var tableDS = {
  autoQuery: true,
  selection: false,
  dataKey: 'content',
  queryFields: [// {
  //   name: 'dataSourceLov',
  //   type: 'object',
  //   label: intl.get('cpfm.dsRoutes.model.dsRoutes.datasourceName').d('数据源'),
  //   lovCode: 'CPFM.DATASOURCE',
  //   ignore: 'always',
  //   noCache: true,
  // },
  // {
  //   name: 'datasourceId',
  //   type: 'string',
  //   bind: 'dataSourceLov.datasourceId',
  // },
  {
    name: 'serviceLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.fullSourceUrl').d('服务'),
    lovCode: 'CADM.SERVICE',
    ignore: 'always',
    noCache: true
  }, {
    name: 'serviceCode',
    type: 'string',
    bind: 'serviceLov.serviceCode'
  }, {
    name: 'tenantLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.tenantId').d('租户'),
    lovCode: 'CPFM.TENANT',
    ignore: 'always',
    noCache: true
  }, {
    name: 'tenantNum',
    type: 'string',
    bind: 'tenantLov.tenantNum'
  }, {
    name: 'method',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.method').d('METHOD'),
    lookupCode: 'CIAM.REQUEST_METHOD'
  }, {
    name: 'enabledFlag',
    type: 'string',
    label: intl.get('cpaas.common.status').d('状态'),
    lookupCode: 'CPFM.ENABLED_FLAG'
  }, {
    name: 'url',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.url').d('URL')
  }],
  fields: [{
    name: 'serviceName',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.fullSourceUrl').d('服务')
  }, {
    name: 'tenantName',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.fullTargetUrl').d('租户')
  }, {
    name: 'url',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.url').d('URL')
  }, {
    name: 'method',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.method').d('METHOD')
  }, {
    name: 'dsNames',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.datasourceName').d('数据源')
  }, {
    name: 'enabledFlag',
    type: 'boolean',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.alertName').d('状态'),
    trueValue: 1,
    falseValue: 0
  }],
  transport: {
    read: function read() {
      return {
        url: "".concat(apiPrefix, "/ds-routes"),
        method: 'GET'
      };
    },
    destroy: function destroy(_ref) {
      var data = _ref.data;

      var _ref2 = Array.isArray(data) ? data[0] : {},
          __id = _ref2.__id,
          _status = _ref2._status,
          other = _objectWithoutProperties(_ref2, _excluded);

      return {
        data: other,
        url: "".concat(apiPrefix, "/ds-routes"),
        method: 'DELETE'
      };
    }
  }
};
var detailDS = {
  autoQuery: false,
  autoQueryAfterSubmit: false,
  autoCreate: true,
  fields: [{
    name: 'serviceLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.fullSourceUrl').d('服务'),
    lovCode: 'CADM.SERVICE',
    textField: 'serviceName',
    ignore: 'always',
    noCache: true
  }, {
    name: 'applicationServiceId',
    type: 'string',
    bind: 'serviceLov.serviceId'
  }, {
    name: 'serviceName',
    type: 'string',
    bind: 'serviceLov.serviceName'
  }, {
    name: 'serviceCode',
    type: 'string',
    bind: 'serviceLov.serviceCode'
  }, {
    name: 'tenantLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.tenantId').d('租户'),
    lovCode: 'CPFM.TENANT',
    ignore: 'always',
    textField: 'tenantName',
    noCache: true
  }, {
    name: 'applicationTenantId',
    type: 'string',
    bind: 'tenantLov.tenantId'
  }, {
    name: 'tenantId',
    type: 'string',
    bind: 'tenantLov.tenantId'
  }, {
    name: 'tenantName',
    type: 'string',
    bind: 'tenantLov.tenantName'
  }, {
    name: 'tenantNum',
    type: 'string',
    bind: 'tenantLov.tenantNum'
  }, {
    name: 'enabledFlag',
    type: 'boolean',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.enabledFlag').d('是否启用'),
    defaultValue: 0,
    trueValue: 1,
    falseValue: 0
  }, {
    name: 'url',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.url').d('URL')
  }, {
    name: 'methodList',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.method').d('METHOD'),
    lookupCode: 'CIAM.REQUEST_METHOD'
  }],
  transport: {
    read: function read(_ref3) {
      var dataSet = _ref3.dataSet;
      var dsRouteId = dataSet.queryParameter.dsRouteId;
      return {
        url: "".concat(apiPrefix, "/ds-routes/").concat(dsRouteId),
        method: 'GET',
        data: {},
        params: {}
      };
    },
    create: function create(_ref4) {
      var data = _ref4.data;

      var _ref5 = Array.isArray(data) ? data[0] : {},
          __id = _ref5.__id,
          _status = _ref5._status,
          other = _objectWithoutProperties(_ref5, _excluded2);

      return {
        url: "".concat(apiPrefix, "/ds-routes/save"),
        method: 'POST',
        data: other
      };
    },
    update: function update(_ref6) {
      var data = _ref6.data;

      var _ref7 = Array.isArray(data) ? data[0] : {},
          __id = _ref7.__id,
          _status = _ref7._status,
          other = _objectWithoutProperties(_ref7, _excluded3);

      return {
        url: "".concat(apiPrefix, "/ds-routes/save"),
        method: 'PUT',
        data: other
      };
    }
  }
}; // 详情页面下的表格信息DS

var detailTableDS = {
  selection: false,
  autoQuery: false,
  autoCreate: false,
  fields: [{
    name: 'datasourceCode',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.datasourceName').d('数据源')
  }, {
    name: 'masterFlag',
    type: 'boolean',
    label: intl.get('cpfm.dsRoutes.model.dataSourceApplication.masterFlag').d('是否主数据源'),
    trueValue: 1,
    falseValue: 0,
    defaultValue: 0
  }],
  transport: {
    read: function read() {
      return {
        url: "".concat(apiPrefix, "/ds"),
        method: 'GET'
      };
    },
    destroy: function destroy(_ref8) {
      var data = _ref8.data;
      return {
        url: "".concat(apiPrefix, "/ds"),
        method: 'DELETE',
        data: data[0]
      };
    }
  }
};
var detailTableDetailDS = {
  selection: false,
  autoQuery: false,
  autoCreate: false,
  fields: [{
    name: 'datasourceLov',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.datasourceName').d('数据源'),
    type: 'object',
    required: true,
    lovCode: 'CPFM.DATASOURCE',
    noCache: true,
    ignore: 'always'
  }, {
    name: 'datasourceId',
    type: 'string',
    bind: 'datasourceLov.datasourceId'
  }, {
    name: 'datasourceCode',
    type: 'string',
    bind: 'datasourceLov.datasourceCode'
  }, {
    name: 'masterFlag',
    type: 'boolean',
    label: intl.get('cpfm.dsRoutes.model.dataSourceApplication.masterFlag').d('是否主数据源'),
    trueValue: 1,
    falseValue: 0,
    defaultValue: 0
  }],
  transport: {
    read: function read() {
      return {
        url: "".concat(apiPrefix, "/ds"),
        method: 'GET'
      };
    },
    destroy: function destroy(_ref9) {
      var data = _ref9.data;
      return {
        url: "".concat(apiPrefix, "/ds"),
        method: 'DELETE',
        data: data[0]
      };
    }
  }
};
var pushTableDS = {
  selection: 'multiple',
  autoQuery: false,
  autoCreate: false,
  queryFields: [{
    name: 'serviceLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.fullSourceUrl').d('服务'),
    lovCode: 'CADM.SERVICE',
    ignore: 'always',
    noCache: true
  }, {
    name: 'serviceCode',
    type: 'string',
    bind: 'serviceLov.serviceCode'
  }, {
    name: 'tenantLov',
    type: 'object',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.tenantId').d('租户'),
    lovCode: 'CPFM.TENANT',
    ignore: 'always',
    noCache: true
  }, {
    name: 'tenantNum',
    type: 'string',
    bind: 'tenantLov.tenantId'
  }],
  fields: [{
    name: 'serviceCode',
    type: 'string',
    label: intl.get('cpfm.dsRoutes.model.dsRoutes.serviceCode').d('服务编码')
  }],
  transport: {
    read: function read() {
      return {
        url: "".concat(apiPrefix, "/ds-routes/all-service"),
        method: 'GET'
      };
    }
  }
};
export { tableDS, detailDS, detailTableDS, detailTableDetailDS, pushTableDS };